﻿@model IList<AppDayStat>
@using Stardust.Data.Monitors
@using NewLife;
@using NewLife.Web;
@using XCode;
@using XCode.Configuration;
@using XCode.Membership;
@using NewLife.Cube;
@using System.Web;
@{
    var fact = ViewBag.Factory as IEntityFactory;
    var page = ViewBag.Page as Pager;
    var fields = ViewBag.Fields as IList<FieldItem>;
    var set = ViewBag.PageSetting as PageSetting;
    //var provider = ManageProvider.Provider;
    var appId = page["appId"].ToInt(-1);
}
<table class="table table-bordered table-hover table-striped table-condensed">
    <thead>
        <tr>
            @if (set.EnableSelect)
            {
                <th class="text-center" style="width:10px;"><input type="checkbox" id="chkAll" title="全选" /></th>
            }
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("ID"))">编号</a></th>
            <th class="text-center" style="min-width:80px;"><a href="@Html.Raw(page.GetSortUrl("StatDate"))">统计日期</a></th>
            @if (appId <= 0)
            {
                <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("AppId"))">应用</a></th>
            }
            <th class="text-center">当日监控</th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Names"))">埋点数</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Total"))">总次数</a></th>
            <th class="text-center" title="环比。今天与昨天相比"><a href="@Html.Raw(page.GetSortUrl("RingRate"))">环比</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Errors"))">错误数</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("ErrorRate"))">错误率</a></th>
            <th class="text-center" title="平均耗时。总耗时除以总次数"><a href="@Html.Raw(page.GetSortUrl("Cost"))">平均耗时</a></th>
            <th class="text-center" title="最大耗时。单位毫秒"><a href="@Html.Raw(page.GetSortUrl("MaxCost"))">最大耗时</a></th>
            <th class="text-center" title="最小耗时。单位毫秒"><a href="@Html.Raw(page.GetSortUrl("MinCost"))">最小耗时</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Apis"))">接口数</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Https"))">Http请求</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Dbs"))">数据库</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Mqs"))">消息队列</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Redis"))">Redis缓存</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Others"))">其它</a></th>
            <th class="text-center" style="min-width:134px;"><a href="@Html.Raw(page.GetSortUrl("CreateTime"))">创建时间</a></th>
            <th class="text-center" style="min-width:134px;"><a href="@Html.Raw(page.GetSortUrl("UpdateTime"))">更新时间</a></th>
            @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
            {
                <th class="text-center">操作</th>
            }
        </tr>
    </thead>
    <tbody>
        @foreach (var entity in Model)
        {
            var url1 = $"/Monitors/traceDayStat?appId={entity.AppId}&date={entity.StatDate:yyyy-MM-dd}";
            //var url2 = $"traceData?appId={entity.AppId}&date={entity.StatDate:yyyy-MM-dd}";
            var bgcolor = "";
            if (entity.ErrorRate >= 0.01)
                bgcolor = "danger";
            else if (entity.ErrorRate >= 0.001)
                bgcolor = "warning";
            <tr class="@bgcolor">
                @if (set.EnableSelect)
                {
                    <td class="text-center"><input type="checkbox" name="keys" value="@entity.ID" /></td>
                }
                <td class="text-center">@entity.ID</td>
                <td class="text-center">@entity.StatDate.ToString("yyyy-MM-dd")</td>
                @if (appId <= 0)
                {
                    <td>@entity.AppName</td>
                }
                <td class="text-center"><a href="@url1" title="@(entity.AppName)监控。应用各个操作名在该日的监控数据" target="_frame">当日监控</a></td>
                <td class="text-right">@entity.Names.ToString("n0")</td>
                <td class="text-right">@entity.Total.ToString("n0")</td>
                <td class="text-right">@entity.RingRate.ToString("p2")</td>
                <td class="text-right">@entity.Errors.ToString("n0")</td>
                <td class="text-right">@entity.ErrorRate.ToString("p2")</td>
                <td class="text-right">@entity.Cost.ToString("n0")</td>
                <td class="text-right">@entity.MaxCost.ToString("n0")</td>
                <td class="text-right">@entity.MinCost.ToString("n0")</td>
                <td class="text-right"><a href="@url1&type=api">@entity.Apis.ToString("n0")</a></td>
                <td class="text-right"><a href="@url1&type=http">@entity.Https.ToString("n0")</a></td>
                <td class="text-right"><a href="@url1&type=db">@entity.Dbs.ToString("n0")</a></td>
                <td class="text-right"><a href="@url1&type=mq">@entity.Mqs.ToString("n0")</a></td>
                <td class="text-right"><a href="@url1&type=redis">@entity.Redis.ToString("n0")</a></td>
                <td class="text-right"><a href="@url1&type=other">@entity.Others.ToString("n0")</a></td>
                <td class="text-center">@entity.CreateTime.ToFullString("")</td>
                <td class="text-center">@entity.UpdateTime.ToFullString("")</td>
                @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
                {
                    <td class="text-center">
                        @await Html.PartialAsync("_List_Data_Action", (Object)entity)
                    </td>
                }
            </tr>
        }
        @if (page.State is AppDayStat)
        {
            var entity = page.State as AppDayStat;
            entity.Valid(false);
            <tr>
                @if (set.EnableSelect)
                {
                    <td></td>
                }
                <td class="text-center">总计</td>
                <td></td>
                @if (appId <= 0)
                {
                    <td></td>
                }
                <td></td>
                <td class="text-right">@entity.Names.ToString("n0")</td>
                <td class="text-right">@entity.Total.ToString("n0")</td>
                <td class="text-right">@entity.RingRate.ToString("p2")</td>
                <td class="text-right">@entity.Errors.ToString("n0")</td>
                <td class="text-right">@entity.ErrorRate.ToString("p2")</td>
                <td class="text-right">@entity.Cost.ToString("n0")</td>
                <td class="text-right">@entity.MaxCost.ToString("n0")</td>
                <td class="text-right">@entity.MinCost.ToString("n0")</td>
                <td class="text-right">@entity.Apis.ToString("n0")</td>
                <td class="text-right">@entity.Https.ToString("n0")</td>
                <td class="text-right">@entity.Dbs.ToString("n0")</td>
                <td class="text-right">@entity.Mqs.ToString("n0")</td>
                <td class="text-right">@entity.Redis.ToString("n0")</td>
                <td class="text-right">@entity.Others.ToString("n0")</td>
                <td></td>
                <td></td>

                @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
                {
                    <td></td>
                }
            </tr>
        }
    </tbody>
</table>